//
//  TappayCartItem.swift
//  tappay_charge
//
//  Created by Warren L on 2024/7/18.
//

struct CartItem {
    var name: String
    var price: Double
    var isPending: Bool?
  
    init(name: String, price: Double, isPending: Bool?) {
        self.name = name
        self.price = price
        self.isPending = isPending
    }
  
    func toDictionary() -> [String: Any] {
        return [
            "name": name,
            "price": price,
            "isPending": isPending ?? false,
        ]
    }
  
    static func fromDictionary(_ dictionary: [String: Any]) -> CartItem? {
        guard let name = dictionary["name"] as? String,
              let price = dictionary["price"] as? Double else {
            return nil
        }
        
        let isPending = dictionary["isPending"] as? Bool
        return CartItem(name: name, price: price, isPending: isPending)
        
    }
}

